#!/bin/bash

SERVERS=( "ftp://ftp.fu-berlin.de/pub/misc/movies/database" \
    "ftp://ftp.funet.fi/pub/mirrors/ftp.imdb.com/pub" \
    "ftp://ftp.sunet.se/pub/tv+movies/imdb" \
    )

FILES=( "actors.list.gz" "actresses.list.gz" "directors.list.gz" \
    "aka-names.list.gz" "aka-titles.list.gz" "genres.list.gz" \
    "movies.list.gz" "writers.list.gz" "producers.list.gz" )

fail=1
srv=0

while [ $fail -eq 1 -a $srv -lt ${#SERVERS[@]} ]; do
    for file in ${FILES[@]}; do
	wget "${SERVERS[$srv]}/$file" -O "${file/.gz/.tmp.gz}"
	if [ $? -ne 0 ]; then
	    fail=1
	    break
	else
	    fail=0
	fi
    done
done

if [ $fail -eq 1 ]; then
    exit 1
fi

gzip -fd *.list.tmp.gz

if [ $? -ne 0 ]; then
    exit 1
fi
